package cn.tedu.smartos.family_user.controller;

import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.family_user.pojo.dto.MedicationReminderAddParam;
import cn.tedu.smartos.family_user.pojo.dto.MedicationReminderUpdateParam;
import cn.tedu.smartos.family_user.pojo.vo.MedicationReminderVO;
import cn.tedu.smartos.family_user.service.MedicationReminderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "用药提醒模块")
@Slf4j
@RestController
@RequestMapping("/api/v1/family_user/medication_reminder")
public class MedicationReminderController {

    @Autowired
    private MedicationReminderService medicationReminderService;

    @ApiOperation("添加用药提醒")
    @PostMapping("/add")
    public JsonResult addMedicationReminder(@RequestBody MedicationReminderAddParam addParam) {
        Long reminderId = medicationReminderService.addMedicationReminder(addParam);
        return JsonResult.ok(reminderId);
    }

    @ApiOperation("更新用药提醒")
    @PostMapping("/update")
    public JsonResult updateMedicationReminder(@RequestBody MedicationReminderUpdateParam updateParam) {
        medicationReminderService.updateMedicationReminder(updateParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除用药提醒")
    @PostMapping("/delete/{reminderId}")
    public JsonResult deleteMedicationReminder(@PathVariable Long reminderId) {
        medicationReminderService.deleteMedicationReminder(reminderId);
        return JsonResult.ok();
    }

    @ApiOperation("获取单个用药提醒")
    @GetMapping("/{reminderId}")
    public JsonResult getMedicationReminderById(@PathVariable Long reminderId) {
        MedicationReminderVO vo = medicationReminderService.getMedicationReminderById(reminderId);
        return JsonResult.ok(vo);
    }

    @ApiOperation("获取老人的用药提醒列表")
    @GetMapping("/list/{elderlyUserId}")
    public JsonResult listMedicationReminders(@PathVariable Long elderlyUserId) {
        List<MedicationReminderVO> list = medicationReminderService
                .listMedicationRemindersByElderly(elderlyUserId);
        return JsonResult.ok(list);
    }

    @ApiOperation("启用/禁用用药提醒")
    @PostMapping("/toggleStatus")
    public JsonResult toggleReminderStatus(
            @RequestParam Long reminderId,
            @RequestParam Integer isActive) {
        medicationReminderService.toggleReminderStatus(reminderId, isActive);
        return JsonResult.ok();
    }
    @ApiOperation("获取所有用药提醒")
    @GetMapping("/all")
    public JsonResult listAllMedicationReminders() {
        List<MedicationReminderVO> list = medicationReminderService.listAllMedicationReminders();
        return JsonResult.ok(list);
    }

    @ApiOperation("获取当前家属用户的用药提醒列表")
    @GetMapping("/listByFamily")
    public JsonResult listMedicationRemindersByFamily(@RequestParam Long familyUserId) {
        List<MedicationReminderVO> list = medicationReminderService
                .listMedicationRemindersByFamilyUser(familyUserId);
        return JsonResult.ok(list);
    }
}